package com.business.corp;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.frame.struts.ActionContext;
import com.frame.struts.BaseBean;
import com.utils.CommUtil;

public class CompanyForm extends BaseBean
{
    public CompanyForm()
    {

    }

    CompanyEntity companyEntity = new CompanyEntity();

    public String addCompany()
    {
        if( logger.isDebugEnabled() )
        {
            logger.debug( "enter addCompany()" );
        }
        HttpServletRequest request = ActionContext.getActionContext()
                                                  .getRequest();
        HttpServletResponse response = ActionContext.getActionContext()
                                                    .getResponse();
        CompanyFactory factory = CompanyFactory.getInstance();
        companyEntity.setOptdate( new Date() );
        companyEntity.setOptrid( CommUtil.getUserId( request ) );
        try
        {
            if( factory.addCompany( companyEntity ) )
            {
                System.out.println( "Enter addCompany()" );
                response.sendRedirect( "back/querycompany.jsp" );
            }
            else
            {
                response.sendRedirect( "/failed.jsp" );
            }
        }
        catch( Exception e )
        {
        }
        return null;

    }

    public String editCompany()
    {
        if( logger.isDebugEnabled() )
        {
            logger.debug( "enter addCompany()" );
        }
        HttpServletRequest request = ActionContext.getActionContext()
                                                  .getRequest();
        HttpServletResponse response = ActionContext.getActionContext()
                                                    .getResponse();
        CompanyFactory factory = CompanyFactory.getInstance();
        companyEntity.setOptdate( new Date() );
        companyEntity.setOptrid( CommUtil.getUserId( request ) );
        try
        {
            factory.updateCompany( companyEntity );
            response.sendRedirect( "back/querycompany.jsp" );
        }
        catch( Exception e )
        {
            e.printStackTrace();
        }
        return null;
    }

    public int getCompanyid()
    {
        return companyEntity.getCompanyid();
    }

    public void setCompanyid( int companyid )
    {
        companyEntity.setCompanyid( companyid );
    }

    public String getCompanyName()
    {
        return companyEntity.getCompanyName();
    }

    public void setCompanyName( String companyName )
    {
        companyEntity.setCompanyName( companyName );
    }

    public String getComment()
    {
        return companyEntity.getComment();
    }

    public void setComment( String comment )
    {
        companyEntity.setComment( comment );
    }

}
